/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package au.edu.swin.swinvehicle.managers;

import au.edu.swin.swinvehicle.bookingtype.BookingTypeManagerRemote;
import au.edu.swin.swinvehicle.bookingtype.BookingTypeTO;
import au.edu.swin.swinvehicle.corporateclient.CorporateClientManagerRemote;
import au.edu.swin.swinvehicle.corporateclient.CorporateClientTO;
import au.edu.swin.swinvehicle.eventtype.EventTypeManagerRemote;
import au.edu.swin.swinvehicle.eventtype.EventTypeTO;
import au.edu.swin.swinvehicle.vehicle.VehicleManagerRemote;
import au.edu.swin.swinvehicle.vehicle.VehicleTO;
import au.edu.swin.swinvehicle.vehiclebooking.VehicleBookingDetailedTO;
import au.edu.swin.swinvehicle.vehiclebooking.VehicleBookingManagerRemote;
import au.edu.swin.swinvehicle.vehicletype.VehicleTypeManagerRemote;
import au.edu.swin.swinvehicle.vehicletype.VehicleTypeTO;
import com.sun.org.apache.commons.logging.Log;
import com.sun.org.apache.commons.logging.LogFactory;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.model.SelectItem;

/**
 *
 * @author Administrator
 */

public class VehicleBookingJSFManagedBean {

    private static Log log = LogFactory.getLog(VehicleBookingJSFManagedBean.class);
    @EJB
    private VehicleBookingManagerRemote vehicleBookingManagerBean;

    @EJB
    private VehicleTypeManagerRemote vehicleTypeManagerBean;

    @EJB
    private EventTypeManagerRemote eventTypeManagerBean;

    @EJB
    private BookingTypeManagerRemote bookingTypeManagerBean;

    @EJB
    private VehicleManagerRemote vehicleManagerBean;

    @EJB
    private CorporateClientManagerRemote corporateClientManagerBean;

    private VehicleBookingDetailedTO vehicleBooking;
    
    /** Creates a new instance of VehicleBookingJSFManagedBean */
    public VehicleBookingJSFManagedBean() {
        this.vehicleBooking = new VehicleBookingDetailedTO();
    }

    public String addVehicleBooking() {
        try {
            this.vehicleBookingManagerBean.addVehicleBooking(this.vehicleBooking);
            // TODO: Pass the success message back to view
            return "success_addVehicleBooking";
        } catch (Exception e) {
            log.error("Cannot add Vehicle Booking", e);
            // TODO: Pass the error message back to view
            return "error";
        }
    }

    public VehicleBookingDetailedTO getVehicleBooking() {
        return vehicleBooking;
    }

    public void setVehicleBooking(VehicleBookingDetailedTO vehicleBooking) {
        this.vehicleBooking = vehicleBooking;
    }

    public List<SelectItem> getVehicleTypes() {
        List<SelectItem> selectItems = new ArrayList<SelectItem>();
        selectItems.add(new SelectItem(null, "--- Select Vehicle type ---"));
        try {
            List<VehicleTypeTO> vehicleTypes = this.vehicleTypeManagerBean.getAllVehicleTypes();
            for (VehicleTypeTO vehicleType : vehicleTypes) {
                selectItems.add(new SelectItem(vehicleType.getId(), vehicleType.getCode()));
            }
        } catch (Exception e) {
            // TODO: Pass the error message back to view
            log.error("Cannot get all Vehicle Types", e);
        }

        return selectItems;

    }

   public List<SelectItem> getEventTypes() {
        List<SelectItem> selectItems = new ArrayList<SelectItem>();
        selectItems.add(new SelectItem(null, "--- Select Event type ---"));
        try {
            List<EventTypeTO> eventTypes = this.eventTypeManagerBean.getAllEventTypes();
            for (EventTypeTO eventType : eventTypes) {
                selectItems.add(new SelectItem(eventType.getId(), eventType.getCode()));
            }
        } catch (Exception e) {
            // TODO: Pass the error message back to view
            log.error("Cannot get all Event Types", e);
        }

        return selectItems;

    }

     public List<SelectItem> getBookingTypes() {
        List<SelectItem> selectItems = new ArrayList<SelectItem>();
        selectItems.add(new SelectItem(null, "--- Select Booking type ---"));
        try {
            List<BookingTypeTO> bookingTypes = this.bookingTypeManagerBean.getAllBookingTypes();
            for (BookingTypeTO bookingType : bookingTypes) {
                selectItems.add(new SelectItem(bookingType.getId(), bookingType.getCode()));
            }
        } catch (Exception e) {
            // TODO: Pass the error message back to view
            log.error("Cannot get all Booking Types", e);
        }

        return selectItems;

    }

       public List<SelectItem> getVehicles() {
        List<SelectItem> selectItems = new ArrayList<SelectItem>();
        selectItems.add(new SelectItem(null, "--- Select Vehicle ---"));
        try {
            List<VehicleTO> vehicles = this.vehicleManagerBean.getAllVehicles();
            for (VehicleTO vehicle : vehicles) {
                selectItems.add(new SelectItem(vehicle.getId(), vehicle.getName()));
            }
        } catch (Exception e) {
            // TODO: Pass the error message back to view
            log.error("Cannot get all Vehicles", e);
        }

        return selectItems;

    }

     public List<SelectItem> getCorporateClients() {
        List<SelectItem> selectItems = new ArrayList<SelectItem>();
        selectItems.add(new SelectItem(null, "--- Select CorporateClient ---"));
        try {
            List<CorporateClientTO> corporateClients = this.corporateClientManagerBean.getAllCorporateClients();
            for (CorporateClientTO corporateClient : corporateClients) {
                selectItems.add(new SelectItem(corporateClient.getId(), corporateClient.getName()));
            }
        } catch (Exception e) {
            // TODO: Pass the error message back to view
            log.error("Cannot get all CorporateClients", e);
        }

        return selectItems;

    }
}
